package de.yvert.jingle.tools;

import java.io.FileInputStream;
import java.io.IOException;

import de.yvert.jingle.Image2D;
import de.yvert.jingle.ImageReader;
import de.yvert.jingle.ReaderWriterFactory;
import de.yvert.jingle.hdr.HdrImage2D;

public class Main
{

private static void load(String filename) throws IOException
{
	long t = System.currentTimeMillis();
	FileInputStream in = new FileInputStream(filename);
	int i = filename.lastIndexOf('.');
	String extension = filename.substring(i+1);
	Image2D image;
	ImageReader reader = ReaderWriterFactory.getReader(extension);
	image = reader.load(in);
	HdrImage2D hdrImage = image.toHDR();
	t = System.currentTimeMillis()-t;
	String title = filename;
	title += " (" + image.getWidth() + "," + image.getHeight() + ")";
	title += " " + (t/1000.0) + "s"; 
	new ImageViewer(hdrImage, title);
	
//	new ExrWriter(new FileOutputStream("test.exr")).write(hdrImage);
}

public static void main(String[] args) throws IOException
{
	if (args.length > 0)
	{
		for (int i = 0; i < args.length; i++)
			load(args[i]);
	}
	else
		load("Samples/memorial.exr");
}

}
